home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / Viewers / aa_m68k_Intel_Only / ToyViewer1.2 / Source / hpcdtoppm.tproj / tools.c < prev   
Encoding:
C/C++ Source or Header  |  1995-08-14  |  3.4 KB  |  183 lines

  1. /* hpcdtoppm (Hadmut's pcdtoppm) v0.6
  2. *  Copyright (c) 1992, 1993, 1994 by Hadmut Danisch (danisch@ira.uka.de).
  3. *  Permission to use and distribute this software and its
  4. *  documentation for noncommercial use and without fee is hereby granted,
  5. *  provided that the above copyright notice appear in all copies and that
  6. *  both that copyright notice and this permission notice appear in
  7. *  supporting documentation. It is not allowed to sell this software in 
  8. *  any way. This software is not public domain.
  9. */
  10.  
  11. #include "hpcdtoppm.h"
  12.  
  13.  
  14. void halve(implane *p)
  15.  {dim w,h,x,y;
  16.   uBYTE *optr,*nptr;
  17.  
  18.   melde("halve\n");
  19.   if ((!p) || (!p->im)) error(E_INTERN);
  20.  
  21.   w=p->iwidth/=2;      
  22.   h=p->iheight/=2;     
  23.  
  24.  
  25.   for(y=0;y<h;y++)
  26.    {
  27.     nptr=(p->im) +   y*(p->mwidth);
  28.     optr=(p->im) + 2*y*(p->mwidth);
  29.  
  30.     for(x=0;x<w;x++,nptr++,optr+=2)
  31.      { *nptr = *optr;
  32.      }
  33.  
  34.    }
  35.  
  36.  }
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44. void interpolate(implane *p)
  45.  {dim w,h,x,y,yi;
  46.   uBYTE *optr,*nptr,*uptr;
  47.  
  48.   melde("interpolate\n");
  49.   if ((!p) || (!p->im)) error(E_INTERN);
  50.  
  51.   w=p->iwidth;
  52.   h=p->iheight;
  53.  
  54.   if(p->mwidth  < 2*w ) error(E_INTERN);
  55.   if(p->mheight < 2*h ) error(E_INTERN);
  56.  
  57.  
  58.   p->iwidth=2*w;
  59.   p->iheight=2*h;
  60.  
  61.  
  62.   for(y=0;y<h;y++)
  63.    {yi=h-1-y;
  64.     optr=p->im+  yi*p->mwidth + (w-1);
  65.     nptr=p->im+2*yi*p->mwidth + (2*w - 2);
  66.  
  67.     nptr[0]=nptr[1]=optr[0];
  68.  
  69.     for(x=1;x<w;x++)
  70.      { optr--; nptr-=2;
  71.        nptr[0]=optr[0];
  72.        nptr[1]=(((sINT)optr[0])+((sINT)optr[1])+1)>>1;
  73.      }
  74.     }
  75.  
  76.   for(y=0;y<h-1;y++)
  77.    {optr=p->im + 2*y*p->mwidth;
  78.     nptr=optr+p->mwidth;
  79.     uptr=nptr+p->mwidth;
  80.  
  81.     for(x=0;x<w-1;x++)
  82.      {
  83.       nptr[0]=(((sINT)optr[0])+((sINT)uptr[0])+1)>>1;
  84.       nptr[1]=(((sINT)optr[0])+((sINT)optr[2])+((sINT)uptr[0])+((sINT)uptr[2])+2)>>2;
  85.       nptr+=2; optr+=2; uptr+=2;
  86.      }
  87.     *(nptr++)=(((sINT)*(optr++))+((sINT)*(uptr++))+1)>>1;
  88.     *(nptr++)=(((sINT)*(optr++))+((sINT)*(uptr++))+1)>>1;
  89.    }
  90.  
  91.  
  92.   optr=p->im + (2*h-2)*p->mwidth;
  93.   nptr=p->im + (2*h-1)*p->mwidth;
  94.   for(x=0;x<w;x++)
  95.    { *(nptr++) = *(optr++);  *(nptr++) = *(optr++); }
  96.  
  97.  }
  98.  
  99.  
  100.  
  101.  
  102. static sINT testbegin(void)
  103.  {sINT i,j;
  104.   for(i=j=0;i<32;i++)
  105.     if(sbuffer[i]==0xff) j++;
  106.  
  107.   return (j>30);
  108.   
  109.  }
  110.  
  111.  
  112. sINT Skip4Base(void)
  113.  {sINT cd_offset,cd_offhelp;
  114.   
  115.   cd_offset = L_Head + L_Base16 + L_Base4 + L_Base ;
  116.   SEEK(cd_offset+3);          
  117.   EREADBUF;    
  118.   cd_offhelp=((((sINT)sbuffer[510])<<8)|sbuffer[511]) + 1;
  119.  
  120.   cd_offset+=cd_offhelp;
  121.  
  122.   SEEK(cd_offset);
  123.   EREADBUF;
  124.   while(!testbegin())
  125.    {cd_offset++;
  126.     EREADBUF;
  127.    }
  128.   return cd_offset;
  129.  }
  130.  
  131.  
  132.  
  133.  
  134.  
  135. void planealloc(implane *p, dim width, dim height)
  136.  {melde("planealloc\n");
  137.  
  138.   p->iwidth=p->iheight=0;
  139.   p->mwidth=width;
  140.   p->mheight=height;
  141.  
  142.   p->mp = ( p->im = ( uBYTE * ) malloc  (width*height*sizeof(uBYTE)) );
  143.   if(!(p->im)) error(E_MEM);
  144.  }
  145.  
  146.  
  147.  
  148.  
  149. /* Test Data types for their size an whether they 
  150.    are signed / unsigned */
  151.  
  152. void typecheck(void)
  153.  { sBYTE sbyte;
  154.    uBYTE ubyte;
  155.    sINT  sint;
  156.    uINT  uint;
  157.  
  158.  
  159.    if(sizeof(sBYTE) != 1) error(E_CONFIG);
  160.    sbyte=126; sbyte++; sbyte++;
  161.    if(sbyte > 126 ) error(E_CONFIG);
  162.  
  163.    if(sizeof(uBYTE) != 1) error(E_CONFIG);
  164.    ubyte=126; ubyte++; ubyte++;
  165.    if(ubyte < 126 ) error(E_CONFIG);
  166.  
  167. #ifdef U_TOO_LONG
  168.    if(sizeof(sINT) < 4) error(E_CONFIG);
  169.    if(sizeof(uINT) < 4) error(E_CONFIG);
  170. #else
  171.    if(sizeof(sINT) != 4) error(E_CONFIG);
  172.    if(sizeof(uINT) != 4) error(E_CONFIG);
  173. #endif
  174.  
  175.    sint=1; sint--; sint--;
  176.    if(sint>1) error(E_CONFIG);
  177.  
  178.    uint=1; uint--; uint--;
  179.    if(uint<1) error(E_CONFIG);
  180.  
  181.  }
  182.  
  183.